import os
import sys
from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QVBoxLayout, QWidget, QSlider, QTextEdit,QHBoxLayout,QLabel,QLineEdit,QWidgetItem,QWidget
from PySide6.QtCore import Qt, QTimer,QSize,QThread, Signal
import requests
import sounddevice as sd
from scipy.io.wavfile import write
import scipy.io.wavfile as wavfile
import numpy as np
import time
from AudioPlayerWidget import AudioPlayerWidget
from httpclienttoche import HttpClientToChe
import asyncio
from PySide6.QtGui import QPixmap
import aiohttp
import PyPDF2
import docx
import qdarkstyle
class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("虚拟面试制管理者后台")
        self.initUI()
        self.httpserver=HttpClientToChe()
        self.loop = asyncio.new_event_loop()
        asyncio.set_event_loop(self.loop)
        asyncio.run(self.start())
       # message_text=self.httpserver.create_bigdl_chat_question("产品经理")
        pass

    async def start(self):
        response = requests.request("GET", "https://openapi.sophnet.com/bjriscv/server2/v1/start")  
        pass
    def initUI(self):
        # 创建一个垂直布局的容器
        image_label = QLabel()

# 使用QPixmap加载图片
        pixmap = QPixmap('girl.png')  # 替换为你的图片文件路径

# 设置图片的缩放方式，这里设置为适应QLabel的大小
        image_label.setPixmap(pixmap.scaled(QSize(350,350), Qt.AspectRatioMode .KeepAspectRatio, Qt.TransformationMode.SmoothTransformation))

# 将QLabel添加到布局管理器
       
        layout1 = QVBoxLayout()
       
        hlayout0 =QHBoxLayout()
        layout1 .addLayout(hlayout0)
        label=QLabel("历史对话")
        hlayout0.addWidget(label)
        hlayout0.addWidget(image_label)
        # 创建带有滑动条的文本显示框
        self.text_display = QTextEdit()
        self.text_display.setReadOnly(True)
        self.text_display.setStyleSheet("QTextEdit { background-color: rgb(0.0,0.0,155.0); color: rgb(255,255.0,255.0); font-size:16pf }")
        hlayout0 .addWidget(self.text_display)
        hlayout1 =QHBoxLayout()
        layout1 .addLayout(hlayout1)
        # 创建文本输入框
        label1=QLabel("输入jd")
        hlayout1.addWidget( label1)
        self.text_input = QLineEdit()
        self.send_btn=QPushButton("发送")
        self.send_btn.clicked.connect(self.send_text_input)
        hlayout1.addWidget(self.text_input)
        hlayout1.addWidget( self.send_btn)
        # 设置文本输入框的高度为一行文本的高度
        self.text_input.setFixedHeight(50)
       # self.text_input.textChanged.connect(self.text_input_enter)
        # 创建一个中心窗口的小部件
        central_widget = QWidget()
        central_widget.setLayout(layout1 )
        self.setCentralWidget(central_widget)
        # 创建一个状态指示器，用于更新录音按钮的文字
        self.recording = False
       

    def send_text_input(self):
        inputtext=self.text_input.text()
        message_text=self.httpserver.create_bigdl_chat_question(inputtext)
        self.text_display .setText(message_text)   
        self.text_input.setText(" ")
        pass
       # 函数来读取不同文件类型的内容
 
if __name__ == "__main__":
    app = QApplication(sys.argv)
    app.setStyleSheet(qdarkstyle.load_stylesheet(qt_api='pyside6'))
    window = MainWindow()
    window.show()
    sys.exit(app.exec())       